package com.hangwei.paperless.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.DictBean;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/17.
 */

public abstract class NATypeAdapter extends MyAdapter<DictBean, BaseViewHolder> {


    public NATypeAdapter(@Nullable List<DictBean> data) {
        super(R.layout.item_na, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final DictBean item) {
        ImageView ivChecked = helper.itemView.findViewById(R.id.ivChecked);
        TextView tvTypeName = helper.itemView.findViewById(R.id.tvTypeName);

        ivChecked.setVisibility(item.checked ? View.VISIBLE : View.INVISIBLE);
        tvTypeName.setTextColor(item.checked ? mContext.getResources().getColor(R.color.blue1) : mContext.getResources().getColor(R.color.text));
        tvTypeName.setText(Tools.checkedString(item.code + ":" + item.name));
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!item.checked) {
                    for (DictBean sh : mData) {
                        sh.checked = false;
                    }
                    item.checked = true;
                    notifyDataSetChanged();
                }
                onAdapterItemClick(helper, item);
            }
        });
    }

    protected abstract void onAdapterItemClick(BaseViewHolder helper, DictBean item);
}
